using System;
using System.Collections;
using System.Web;
using Sedna.Core.Controller.Common;

namespace Sedna.Core.Controller.Menu
{
	public class ExecuteDefaultLeftAction : AbstractAction
	{
		public override IActionResult Execute(IExecutionContext executionContext)
		{
			IMenuItem currentTopMenuItem = (IMenuItem)executionContext["infrastructure.CurrentConfiguration"];
			IMenuItem defaultSubMenuItem = currentTopMenuItem.GetDefaultMenuItem();
			if(defaultSubMenuItem == null)
			{
				return new ActionResult(successStatus);
			}
			executionContext["menu_level_1"] = currentTopMenuItem.Id;
			executionContext["menu_level_2"] = defaultSubMenuItem.Id;
			IActionExecutor actionExecutor = (IActionExecutor)SpringContextFactory.GetContext().GetObject("runtime.ActionExecutor");
			actionExecutor.ExecuteAction(executionContext, defaultSubMenuItem, null);
			//TODO: think about proper action chaining here
			return new ActionResult(successStatus);

		}
	}
}
